import Vue from 'vue'  
import Router from 'vue-router'  
import CampusBinhai from '@/views/CampusBinhai'  
import CampusChashan from '@/views/CampusChashan'  
import CampusYueqing from '@/views/CampusYueqing'  
import MyLogin from '@/views/MyLogin'  
import StudentSystem from '@/views/StudentSystem'  
  
Vue.use(Router)  
  
const router = new Router({  
  routes: [  
    {  
      path: '/',  
      name: 'CampusBinhai',  
      component: CampusBinhai  
    },  
    {  
      path: '/chashan',  
      name: 'CampusChashan',  
      component: CampusChashan  
    },  
    {  
      path: '/yueqing',  
      name: 'CampusYueqing',  
      component: CampusYueqing  
    },  
    {  
      path: '/mylogin',  
      name: 'MyLogin',  
      component: MyLogin  
    },  
    {  
      path: '/student-system',  
      name: 'StudentSystem',  
      component: StudentSystem,  
      meta: { requiresAuth: true } 
    }  
  ]  
})  
  

router.beforeEach((to, from, next) => {  
 
  if (to.matched.some(record => record.meta.requiresAuth)) {  
  
    const isLoggedIn = false;  
  
    if (!isLoggedIn) {  
      
      next({  
        path: '/mylogin',  
        query: { redirect: to.fullPath } 
      });  
    } else {  
      next(); 
    }  
  } else {  
    next(); 
  }  
});  
  
export default router;